//
// Created by zhp on 2025/7/17.
//
#include "Dog.h"
#include <iostream>

// 运算符重载
Dog operator+(const Dog &a, const Dog &b) {
//    return Dog(a.age + b.age, "reload dog");
    return {a.age + b.age, "reload dog"};
}

void operator-(Dog &a, Dog &b) {
//    return Dog(a.age + b.age, "reload dog");
    a.age = 1;
    b.age = 1;
}

void operator/(Dog a, Dog b) {
//    return Dog(a.age + b.age, "reload dog");
    a.age = 2;
    b.age = 2;
}

int main() {
    Dog a(11, "jack");
    Dog b(10, "lisi");
//    Dog reload_dog = operator+(a, b);
    Dog reload_dog = a + b;
    std::cout << "age: "
              << reload_dog.age
              << std::endl
              << "name: "
              << reload_dog.name
              << std::endl;

    // 不加const，会修改指针指向的内容数据
    // 类似这样： int *p = &a; *p = 1;
    a - b;
    std::cout << "a age:" << a.age << std::endl << "b.age" << b.age << std::endl;

    // 不加 &，函数知道原对象的首地址，会cp一个副本，操作的是副本的对象，所以没改变
    a - b;
    std::cout << "a age:" << a.age << std::endl << "b.age" << b.age << std::endl;

}

